package newtank.data;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import lombok.EqualsAndHashCode;
import newtank.data.assistant.SyncData;
import server.netty.GpcDataPackage;
import tool.GlobalUniqueGenerator;

/**
 * @author lijiahao
 * @since 2022/3/8
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class MoveOperatorSignal extends AbstractDataPackage {

    private static final long serialVersionUID = -3375925245307780338L;

    private final String MOVE_TYPE = "move_type";
    private final String MOVE_CODE = "move_code";

    /** 操作方向 1-上 2-下 3-左 4-右 **/
    private String type;

    /** 操作编号 **/
    private String moveCode;

    /** 同步包 **/
    private SyncData syncData;

    public MoveOperatorSignal(String unique, String operatorType, String moveCode, SyncData syncData) {
        this.index = GlobalUniqueGenerator.getGlobalId();
        this.status = 1;
        this.length = 0;
        this.code = 10;
        this.unique = unique;
        this.type = operatorType;
        this.moveCode = moveCode;
        this.syncData = syncData;
    }

    @Override
    protected void filledData(GpcDataPackage gpcDataPackage) {
        filledDataHeader(gpcDataPackage, MOVE_TYPE, ""+this.getType());
        filledDataHeader(gpcDataPackage, MOVE_CODE, this.getMoveCode());
        filledDataHeader(gpcDataPackage, SyncData.SYNC_DATA, JSONObject.toJSONString(syncData));
    }
}
